You are here: Resources > Performance Tips > Use Indexes

Use Indexes

An index speeds up the identification of data within a rule or action.

Specify indexes in the input mapping

In the datastore input mapping page, every attribute within a class has a tick box to allow you to specify whether the attribute should be indexed or not. The primary geometry is always indexed.

For Oracle data any other columns with Oracle indexes on them (including primary keys) will be set to be indexed by default.

Defining indexes in the Input Mapping of a datastore

If you need to identify features in a rule or action using an attribute as the initial selection criteria, then you need to tick the box to index that attribute.

Identifying features means anywhere that you need to specify a class of objects other than in the rule or action’s root node (e.g. using a For All, Existence, Aggregate, Chaining or Loop Over Objects construct within a rule or action).

A rule requiring an indexed value

If you are doing a spatial search (i.e. a comparison on the geometry) to identify the nearby features before subsequently checking the ID, then the index on the id is not required. You will only need it when the attribute is used as the initial way to select the set of objects.

Index not required on Building because a small set of objects already identified using another value (in this case a spatial search on the geometry)

While you could just index all attributes just in case, this will require more disk space for the cache while the session is running and will add an overhead to the time taken to open the data within the session.

Use the unmodified value when comparing indexed data

Whenever you use an indexed value (this includes the primary geometry) as the first comparison then don’t apply any built-in functions to the value.

In order to use the index, the comparison needs to run on the raw attribute value itself because this is what has been indexed, not the result of a built-in function.

For example the action displayed below will be very slow because we can’t use the spatial index to identify the admin areas. We are running the outer_ring built-in function on each geometry first which means that every object in the class will need be tested explicitly, rather than using the index on the geometry to reduce the set.

Slow use of outer_ring function

Instead, you may need to add a new initial condition that uses the unmodified value as the first condition, then AND it together with the more specific condition that uses the outer_ring function.

You need to ensure that the first condition finds at least the  features that you want, with as few as possible additional features.

In the example below, the spatial intersects condition will find all areas that are spatially in contact with the line in some way. From this limited subset, we get the outer ring of each one and do the comparison.

Faster use of outer_ring function